home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0040_Deleting Chars from Files.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  70 lines

  1. {
  2. > A friend of mine has a small problem with Binkley connecting, and whenever
  3. > this happens, Binkley writes a bunch of Line noise characters in his log f
  4. > Some of these characters are EOF and EOL markers. I am trying to write a s
  5. > program that will read it, and write the contents to a new file, without a
  6. > the garbage in it. Of course, when I get to the first EOF, my program thin
  7. > it's done.
  8. }
  9.  
  10. Program KillChar;
  11.  
  12. { Written by Tom Carroll and released to the public domain
  13.   on 12/11/93.
  14.  
  15.  This program will read any file and delete any characters passed on
  16.   the command line.
  17.  
  18.   For example:  KillChar InFile OutFile ASCII Value (of character)
  19.  
  20.          i.e.:  KILLCHAR MYFILE.TXT NEWFILE.TXT 12
  21.  
  22.   This will remove all form feeds from a text file.
  23.  
  24.   No error control is included.
  25.  
  26. }
  27.  
  28. VAR
  29.    Buffer    : ARRAY[0..255] OF Char;
  30.    TmpString,
  31.    StringVar : STRING;
  32.    FileLoc,
  33.    NumBytes  : LongInt;
  34.    InFile,
  35.    OutFile   : FILE;
  36.    NumRead   : Integer;
  37.    StringPos : Integer;
  38.  
  39. BEGIN
  40.    Val(ParamStr(3), NumRead, StringPos);
  41.    TmpString := Chr(NumRead); {#26;}
  42.    Assign(InFile, ParamStr(1));
  43.    Reset(InFile, 1);
  44.    Assign(OutFile, ParamStr(2));
  45.    Rewrite(OutFile, 1);
  46.    NumBytes := FileSize(InFIle);
  47.    WHILE FilePos(InFile) < NumBytes DO
  48.       BEGIN
  49.          FileLoc := FilePos(InFile);
  50.          IF FileLoc < (NumBytes - 255) THEN
  51.             BlockRead(InFile, Buffer, 255, NumRead)
  52.          ELSE
  53.             BlockRead(InFile, Buffer, FileSize(InFile) - FileLoc,
  54.                       NumRead);
  55.          Move(Buffer[0], StringVar[1], NumRead);
  56.          StringVar[0] := Chr(NumRead);
  57.          StringPos := Pos(TmpString, StringVar);
  58.          WHILE StringPos > 0 DO
  59.             BEGIN
  60.                StringPos := Pos(TmpString, StringVar);
  61.                Delete(StringVar, StringPos, 1);
  62.             END;
  63.          StringPos := Length(StringVar);
  64.          Move(StringVar[1], Buffer, Length(StringVar));
  65.          BlockWrite(OutFile, Buffer, Length(StringVar));
  66.       END;
  67.    Close(InFile);
  68.    Close(OutFIle);
  69. END.
  70.